//
//  YYEVisitorViewController.swift
//  weibo14
//
//  Created by mac on 16/3/3.
//  Copyright © 2016年 mac. All rights reserved.
//  tableView的基类

import UIKit

class YYEVisitorViewController: UITableViewController {


    // 用户是否登陆
    var userlogon: Bool = YYEUserAccountViewModel.sharedAccountViewModel.uesrLogon
    
    
    
    
    override func loadView() {
        
        if userlogon { //登陆了
            // 加载父类的tableView
            super.loadView()
        } else { // 没有登陆
            // 如果没有登录,那么就登录我们的访客视图
            setupVisitorView()
        }
    }
    
    private func setupVisitorView() {
    
        view = visitorView
    
        
        
        // 设置左右两侧的
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆",  target: self, action: "login")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册",  target: self, action: "login")
        
        
    }
    @objc private func login() {
    
        // print("登陆个注册")
   
        // 弹出控制器
        let vc = YYEOAuthViewController()
        
        presentViewController(YYENavigationController(rootViewController:vc), animated: true, completion: nil)
    
    
    }
    
     lazy var visitorView:YYEVisitorView = {
    
        let v = YYEVisitorView()
        
        // 代理方法
        v.delegate = self
        
        return v
    }()

}

extension YYEVisitorViewController:YYEVisitorViewDelegate {

    func visitorView(visitorView: YYEVisitorView, loginButtonDidCliked: UIButton) {
        
        // print("代理成功了")
        login()
        
    }
    


}






